#ifndef BASESTATIONMODEL_H
#define BASESTATIONMODEL_H

#include <QAbstractListModel>
#include <QTimer>
#include <QVariantMap>
#include <QRandomGenerator>

struct BaseStation {
    QString id;
    QString name;
    double latitude;
    double longitude;
    QString status; // "normal", "warning", "critical", "offline"
    double signalStrength;
    int connectedUsers;
};

class BaseStationModel : public QAbstractListModel
{
    Q_OBJECT

public:
    enum Roles {
        IdRole = Qt::UserRole + 1,
        NameRole,
        LatitudeRole,
        LongitudeRole,
        StatusRole,
        SignalStrengthRole,
        ConnectedUsersRole
    };

    explicit BaseStationModel(QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;

    Q_INVOKABLE QVariantMap getStationInfo(int index) const;
    Q_INVOKABLE int getAbnormalCount() const;
    Q_INVOKABLE double getAvgSignalQuality() const;

signals:
    void statisticsChanged(int abnormalCount, double avgSignal);
    void stationAlarm(const QString &stationId, const QString &message, const QString &severity);
    void stationStatusChanged(const QString &stationId, const QString &oldStatus, const QString &newStatus);

private slots:
    void updateStations();

private:
    void initializeStations();

    QList<BaseStation> m_stations;
    QTimer *m_updateTimer;
};

#endif // BASESTATIONMODEL_H

